#!/bin/bash
#功能：打印所有检测项

#查询命令
cat <<EOF |grep -Ev "^$|^#">/tmp/print.conf
cat /etc/passwd |grep -Ev 'nologin|false'
sed -n '/pam_cracklib.so/p'/etc/pam.d/common-password 
sed -n '/pam_tally2.so/p' /etc/pam.d/common-auth
cat /etc/login.defs |grep PASS
EOF
######################################################
DATE_FT=`date +%F_%H%M%S`

SHPATH=`readlink -f $0`
SHDIR=`dirname $SHPATH`
SHNAME="$0"

#DIR
LOG_DIR=$SHDIR/logs/$SHNAME
TMP_DIR=$SHDIR/temp/$SHNAME
OUT_DIR=$SHDIR/out/$SHNAME
mkdir -p $LOG_DIR $TMP_DIR $OUT_DIR

OUT_FILE=$OUT_DIR/print_check_out.$DATE_FT.txt


USERNAME_VAR=`whoami`
HOSTNAME_VAR=`hostname`
PS1_VAR=`echo $PS1`
HNAME=`echo $HOSTNAME_VAR|tr '.' '\n'|tr ' ' '\n'`
echo $PS1_VAR|grep ':' >/dev/null
if [ $? -eq 0 ];then  PS1_NEW=$HOSTNAME_VAR@$HNAME':~/Desktop#';else PS1_NEW='['$HOSTNAME_VAR@$HNAME' Desktop]#';fi
echo "用户名：$USERNAME_VAR"
echo "主机名：$HOSTNAME_VAR"
echo "PS1为：$PS1_VAR"
echo "拼合PS1为：$PS1_NEW"
read -p "请确认PS1是否正确(回车/或者直接输入新的提示符):" KEY
if [  -z "$KEY"  ];then echo ;else PS1_NEW="$KEY";fi
echo "确认PS1提示符为：$PS1_NEW"
echo '------------------------------------------------'
>$OUT_FILE
while read LINE
do

echo "$LINE |grep -v ^#" > /tmp/test.sh
echo "
================================================================
开始执行命令：$LINE
----------------------------------------------------------------" >>$OUT_FILE
echo "$PS1_NEW $LINE" >>$OUT_FILE
bash /tmp/test.sh >>$OUT_FILE
if [ ! $? -eq 0 ];then echo "Error! 执行命令失败： $LINE" |tee -a $OUT_FILE;fi 
echo
done < /tmp/print.conf
echo
echo "OUT:$OUT_FILE"